home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 729 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  5.7 KB

  1. Path: news.cyberport.com!usenet
  2. From: tkennedy@cyberport.com (Warren Young)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Hungarian notation
  5. Date: Sat, 06 Jan 1996 17:31:21 GMT
  6. Organization: Kennedy and Associates
  7. Message-ID: <4cmblb$hj2@macaw.cyberport.com>
  8. References: <cmanDK7x13.5KM@netcom.com> <verec-2712952049000001@ppp30.micronet.fr> <30E39BC0.3BAE@zeta.org.au> <verec-2912950003390001@ppp05.micronet.fr> <30E55183.52FF@zeta.org.au> <4c44dh$771@mujibur.inmind.com> <4c477m$ou4@macaw.cyberport.com> <4ccq2u$3e3@mujibur.inmind.com>
  9. NNTP-Posting-Host: ppp3.cyberport.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. mfinney@inmind.com wrote:
  13.  
  14. >In <4c477m$ou4@macaw.cyberport.com>, tkennedy@cyberport.com (Warren Young) writes:
  15. >>mfinney@inmind.com wrote:
  16.  
  17. >>Sure the semantics change.  Try passing the latter to printf() and see
  18. >>how broken the program gets.  Or strlen(), or strtou()...  Granted,
  19. >>you're likely to be changing the string manipulation functions at the
  20. >>same time, but this is one place where HN becomes useful: helping you
  21. >>find the places where you missed a function call that needs changing.
  22.  
  23. >In all of the cases, except printf(), the function prototypes (everyone
  24. >uses those, right?) will catch any type change which is incorrect.  And
  25.  
  26. Of course.  These were merely examples of well-known functions where
  27. passing the new string would cause problems.  You asserted that the
  28. semantics didn't change, and I just dashed off some examples that
  29. disproved that.
  30.  
  31. >printf() is kinda obsolete.  If you are dealing with wide character types
  32. >you are almost certainly not going to be using printf().  
  33.  
  34. Your example was converting an existing "standard" string into a wide
  35. character string by prefixing it with L.  So, it's very likely that
  36. the original program was using something that wanted regular strings,
  37. and the change will probably stop it working from right.
  38.  
  39. >But, even if you
  40. >were, a global grep for printf / "insufficientStorage" would catch all of
  41. >those combinations.  So Hungarian notation doesn't buy you much here.
  42.  
  43. Sure, you can do the compile-and-grep thing until it finally compiles,
  44. but this method can fail you, because of the usages can be missed.
  45. Between strong type checking, lack of vararg functions and careful
  46. coding habits, you can be assured that the compiler will catch most of
  47. the problems, but it's always those little things that the compiler
  48. thought were copacetic that get you.
  49.  
  50. If you're using HN, you will be _forced_ to visit every usage of that
  51. variable.  If you care enough about types to be using a
  52. well-considered HN variant (I'm not talking about that Petzoldian
  53. alphabet hash), you'll probably take the opportunity to make sure that
  54. the semantics are still OK.  I know of no better way of encouraging
  55. this than HN.
  56.  
  57. >Type safefty is available in the language.  Those who don't use it get
  58. >what they deserve.
  59.  
  60. I agree, and if this is heeded religiously, it completely solves type
  61. compatibility problems for C++ houses.  In other, less perfect
  62. environments, such as C-only houses and those where you can't count on
  63. everyone to follow the rules, HN is useful.  HN also has another
  64. mission, and that is to encourage programmers to consider semantic
  65. issues more carefully, especially in cases where the code mixes types
  66. and yet compiles without warning.  Your rule does nothing in this
  67. regard.
  68.  
  69. Don't think that I have HN pinned down, though.  I've recently been
  70. refining my HN variant, and with this thread, I have a whole list of
  71. style and usage questions that I want resolved in my version of HN.
  72. Once this thread starts dying (or at least stops giving me questions
  73. to answer), I hope to start on a semi-formal definition of my HN
  74. variant, which I may post.
  75.  
  76. >>>The use of upper case names to distinguish #define names is one
  77. >>>of the worst pseudo-standards that have been fostered upon the
  78. >>>programming community.  Right up there with Hungarian notation.
  79. >>
  80. >>It's very useful with macros, because it tells the reader, "Hey!  The
  81. >>arguments to this macro aren't type-safe and there may be
  82. >>side-effects!"  With C++, though, I have a solution that both of us
  83. >>might find acceptable: dump #defines for consts and inline functions.
  84.  
  85. >... if you have very many global constants
  86. >the use of const data elements can add a LOT of space to the
  87. >compiled program.  Not always acceptable.  With #defines and
  88. >constant folding in the compiler/linker that is less of a problem.
  89.  
  90. The only excuse I can think of for not having constant folding turned
  91. on is if your code is taking and using the address of a constant.  If
  92. you're doing that, though, you have no sense of style anyway.
  93. (Whether by your choice or Fate's, the result is the same.)
  94.  
  95. >And macro functions are still useful -- although much less frequently
  96. >than in the past.  I have used them to "map" a common function to
  97. >different operating systems.  Here, even the inline template function
  98. >doesn't work well.  Further, the code is reduced since the alternate
  99. >operating system code goes away at compile time.  An example of
  100.  
  101. It goes away with inline functions, too, becase you're likely to be
  102. using conditional compilation to switch the various versions of the
  103. inline wrapper in and out.  _I_ would be, anyway....
  104.  
  105. >Another example was the use of printf() in some
  106. >C code.  It turns out that the Microsoft compiler didn't support printf()
  107. >in the library for some types of programs, but you could call a system
  108. >wprintf() to do the same thing (with restricted types, but that was
  109.  
  110. Yes, where you essentially need compile time search and replace,
  111. #defines are useful.  Since you can't wrap a vararg function with an
  112. inline wrapper (or even a proper #define macro (one with arguments)),
  113. you simply have to replace the function name at compile time.  That's
  114. about it, though.
  115.  
  116. = Warren --
  117.  
  118.